/* ----------------------------------------------------------------------
*
* Copyright (C) 2024 XiaoFei. All rights reserved.
*
* $file:        XiaoFei_Vector.h
* $Date:        26-October-2024
* $Revision:    V1.2
* $Project:     XiaoFei DSP Library
*
* -------------------------------------------------------------------- */

#ifndef __XiaoFei_Vector_H
#define __XiaoFei_Vector_H

#ifndef My_ERROR
#define My_ERROR                    0.00000001
#endif
#ifndef My_PI
#define My_PI                       3.14159265
#endif
#ifndef My_EXP_2
#define My_EXP_2                    7.38905609
#endif
#ifndef My_EXP_5
#define My_EXP_5                    148.41315915
#endif
#ifndef My_LOG_2
#define My_LOG_2                    0.69314718
#endif
#ifndef My_LOG_10
#define My_LOG_10                   2.30258509
#endif

#ifndef ResStatus_TypeDef_def
#define ResStatus_TypeDef_def
typedef enum
{ 
    Error       = 0x00,         /*!< The calculation failed */
    Success     = 0x01          /*!< The calculation was successful */
}ResStatus_TypeDef;
#endif

#ifndef Vector_TypeDef_def
#define Vector_TypeDef_def
typedef struct
{
    double* Val ;               /*!< The first address of the vector. */
    unsigned int Size ;         /*!< The size of the vector */
}Vector_TypeDef;
#endif

/*
* @function:    My_VectorCreate
* @parameter:   [in]    size            The size of the vector.
* @parameter:   [in]    data            The data of the vector.
* @return:      The vector memory applied to storage vectors.
*/
Vector_TypeDef My_VectorCreate(unsigned int size, double* data);

/*
* @function:    My_VectorFree
* @parameter:   [in]    *input          The first address of the input vector.
* @return:      None.
*/
void My_VectorFree(Vector_TypeDef* input);

/* 
* @function:    My_VectorAbs
* @parameter:   [in]    *input          The first address of the input vector.
* @parameter:   [out]   *output         The first address of the output vector based on vector absolutions.
* @return:      Successes or failures of the results of the calculations.
*/
ResStatus_TypeDef My_VectorAbs(Vector_TypeDef* input, Vector_TypeDef* output);

/* 
* @function:    My_VectorAdd
* @parameter:   [in]    *inputa         The first address of the input vector.
* @parameter:   [in]    *inputb         The first address of another input vector.
* @parameter:   [out]   *output         The first address of the output vector based on vector additions.
* @return:      Successes or failures of the results of the calculations.
*/
ResStatus_TypeDef My_VectorAdd(Vector_TypeDef* inputa, Vector_TypeDef* inputb, Vector_TypeDef* output);

/* 
* @function:    My_VectorSub
* @parameter:   [in]    *inputa         The first address of the input vector.
* @parameter:   [in]    *inputb         The first address of another input vector.
* @parameter:   [out]   *output         The first address of the output vector based on vector subtraction.
* @return:      Successes or failures of the results of the calculations.
*/
ResStatus_TypeDef My_VectorSub(Vector_TypeDef* inputa, Vector_TypeDef* inputb, Vector_TypeDef* output);

/* 
* @function:    My_VectorDotprod
* @parameter:   [in]    *inputa         The first address of the input vector.
* @parameter:   [in]    *inputb         The first address of another input vector.
* @parameter:   [out]   *output         The result of the dot product of the vector.
* @return:      Successes or failures of the results of the calculations.
*/
ResStatus_TypeDef My_VectorDotprod(Vector_TypeDef* inputa, Vector_TypeDef* inputb, double* output);

/* 
* @function:    My_VectorMul
* @parameter:   [in]    *inputa         The first address of the input vector.
* @parameter:   [in]    *inputb         The first address of another input vector.
* @parameter:   [out]   *output         The first address of the output vector based on vector multiplication.
* @return:      Successes or failures of the results of the calculations.
*/
ResStatus_TypeDef My_VectorMul(Vector_TypeDef* inputa, Vector_TypeDef* inputb, Vector_TypeDef* output);

/* 
* @function:    My_VectorNeg
* @parameter:   [in]    *input          The first address of the input vector.
* @parameter:   [out]   *output         The first address of the output vector based on vector negates.
* @return:      Successes or failures of the results of the calculations.
*/
ResStatus_TypeDef My_VectorNeg(Vector_TypeDef* input, Vector_TypeDef* output);

/* 
* @function:    My_VectorScale
* @parameter:   [in]    *input          The first address of the input vector.
* @parameter:   [in]    a               The scale of the multiplication operation.
* @parameter:   [out]   *output         The first address of the output vector based on vector Scale.
* @return:      Successes or failures of the results of the calculations.
*/
ResStatus_TypeDef My_VectorScale(Vector_TypeDef* input, double a, Vector_TypeDef* output);

/*
* @function:    My_VectorMax
* @parameter:   [in]    *input          The first address of the input vector.
* @parameter:   [out]   *max            The address where the largest value is saved.
* @parameter:   [out]   *address        The address where the largest value in the vector.
* @return:      Successes or failures of the results of the calculations.
*/
ResStatus_TypeDef My_VectorMax(Vector_TypeDef* input, double* max, unsigned int* address);

/*
* @function:    My_VectorMin
* @parameter:   [in]    *input          The first address of the input vector.
* @parameter:   [out]   *min            The address where the smallest value is saved.
* @parameter:   [out]   *address        The address where the smallest value in the vector.
* @return:      Successes or failures of the results of the calculations.
*/
ResStatus_TypeDef My_VectorMin(Vector_TypeDef* input, double* min, unsigned int* address);

/*
* @function:    My_VectorAcc
* @parameter:   [in]    *input          The first address of the input vector.
* @parameter:   [out]   *acc            The address where the accumulate value is saved.
* @return:      Successes or failures of the results of the calculations.
*/
ResStatus_TypeDef My_VectorAcc(Vector_TypeDef* input, double* acc);

/*
* @function:    My_VectorMean
* @parameter:   [in]    *input          The first address of the input vector.
* @parameter:   [out]   *mean           The address where the mean value is saved.
* @return:      Successes or failures of the results of the calculations.
*/
ResStatus_TypeDef My_VectorMean(Vector_TypeDef* input, double* mean);

/*
* @function:    My_VectorPower
* @parameter:   [in]    *input          The first address of the input vector.
* @parameter:   [out]   *power          The address where the power value is saved.
* @return:      Successes or failures of the results of the calculations.
*/
ResStatus_TypeDef My_VectorPower(Vector_TypeDef* input, double* power);

/*
* @function:    My_VectorMeanSquare
* @parameter:   [in]    *input          The first address of the input vector.
* @parameter:   [out]   *meansqu        The address where the mean square value is saved.
* @return:      Successes or failures of the results of the calculations.
*/
ResStatus_TypeDef My_VectorMeanSquare(Vector_TypeDef* input, double* meansquare);

/*
* @function:    My_VectorRms
* @parameter:   [in]    *input          The first address of the input vector.
* @parameter:   [out]   *rms            The address where the root mean square value is saved.
* @return:      Successes or failures of the results of the calculations.
*/
ResStatus_TypeDef My_VectorRms(Vector_TypeDef* input, double* rms);

/*
* @function:    My_VectorVar
* @parameter:   [in]    *input          The first address of the input vector.
* @parameter:   [out]   *var            The address where the variance value is saved.
* @return:      Successes or failures of the results of the calculations.
*/
ResStatus_TypeDef My_VectorVar(Vector_TypeDef* input, double* var);

/*
* @function:    My_VectorStd
* @parameter:   [in]    *input          The first address of the input vector.
* @parameter:   [out]   *std            The address where the standard deviation value is saved.
* @return:      Successes or failures of the results of the calculations.
*/
ResStatus_TypeDef My_VectorStd(Vector_TypeDef* input, double* std);

/*
* @function:    My_VectorConv
* @parameter:   [in]    *inputa         The first address of the input vector.
* @parameter:   [in]    *inputb         The first address of another input vector.
* @parameter:   [out]   *output         The first address of the output vector based on vector convolution.
* @return:      Successes or failures of the results of the calculations.
*/
ResStatus_TypeDef My_VectorConv(Vector_TypeDef* inputa, Vector_TypeDef* inputb, Vector_TypeDef* output);

/*
* @function:    My_VectorLse
* @parameter:   [in]    *input          The first address of the input vector.
* @parameter:   [out]   *lse            The address where the LogSumExp value is saved.
* @return:      Successes or failures of the results of the calculations.
*/
ResStatus_TypeDef My_VectorLse(Vector_TypeDef* input, double* lse);

/*
* @function:    My_BubbleSort
* @parameter:   [in]    *input          The first address of the input vector.
* @parameter:   [out]   *output         The first address of sorted vector.
* @return:      Successes or failures of the results of the calculations.
*/
ResStatus_TypeDef My_BubbleSort(Vector_TypeDef* input, Vector_TypeDef* output);

/*
* @function:    My_SelectionSort
* @parameter:   [in]    *input          The first address of the input vector.
* @parameter:   [out]   *output         The first address of sorted vector.
* @return:      Successes or failures of the results of the calculations.
*/
ResStatus_TypeDef My_SelectionSort(Vector_TypeDef* input, Vector_TypeDef* output);

/*
* @function:    My_InsertionSort
* @parameter:   [in]    *input          The first address of the input vector.
* @parameter:   [out]   *output         The first address of sorted vector.
* @return:      Successes or failures of the results of the calculations.
*/
ResStatus_TypeDef My_InsertionSort(Vector_TypeDef* input, Vector_TypeDef* output);

/*
* @function:    My_ShellSort
* @parameter:   [in]    *input          The first address of the input vector.
* @parameter:   [out]   *output         The first address of sorted vector.
* @return:      Successes or failures of the results of the calculations.
*/
ResStatus_TypeDef My_ShellSort(Vector_TypeDef* input, Vector_TypeDef* output);

/*
* @function:    My_QuickSort
* @parameter:   [in]    *input          The first address of the input vector.
* @parameter:   [out]   *output         The first address of sorted vector.
* @return:      Successes or failures of the results of the calculations.
*/
ResStatus_TypeDef My_QuickSort(Vector_TypeDef* input, Vector_TypeDef* output);

#endif

